#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os


def createFile(dirPath, fileName):
    """检查文件是否存在，不存在新创建一个"""
    dir_exists = os.path.exists(dirPath)
    try:
        if not dir_exists:
            os.makedirs(dirPath)
            os.chdir(dirPath)
            dir_file = os.getcwd() + "/" + fileName
            with open(dir_file, 'w') as file_object:
                file_object.close()
            return "success"
        else:
            os.chdir(dirPath)
            dir_file = os.getcwd() + "/" + fileName
            open(dir_file, 'w')
            return "success"

    except IOError:
        print(IOError)
        return "error"


# 测试方法
filePath = 'E:/data/python/'
fileName = 'programming.txt'
result = createFile(filePath, fileName)
print(result)
